

#include "JW01.h"
#include "stdlib.h"
#include "main.h"

uint8_t JW01_Get_Air_State(uint8_t DATA_BUFF[] , float *TVOC , float *CO2 ,float *CH2O)
{
	uint16_t checksum = 0;
	uint8_t i=0;
	uint8_t j=0;

	// header of Packet
	if( DATA_BUFF[0] != 0x2C )	return 1;
	if( DATA_BUFF[1] != 0xE4 )	return 1;

	//check sum
	for (int i = 0; i < 8; ++i) {
		checksum += DATA_BUFF[i];
	}
	if( DATA_BUFF[8] != (uint8_t)checksum )	return 2;

	/* TVOC*/
	*TVOC = ( DATA_BUFF[2]<<8 | DATA_BUFF[3] )*0.001;

	/* CH2O*/
	*CH2O = ( DATA_BUFF[4]<<8 | DATA_BUFF[5] )*0.001;

	/* CO2*/
	*CO2 = ( DATA_BUFF[6]<<8 | DATA_BUFF[7] )*0.001;

	return 0;
}


